package com.feilong.modules.web.jvm;

/**
 * 检验  虚拟机会保证一个类的<clinit>()方法在多线程环境中被正确加锁和同步。
 */
public class CheckClinit{

    public static void main(String[] args) {
        Runnable r = () -> {
            System.out.println(Thread.currentThread().getName()+"开始");
            InitStatic init = new InitStatic();
            System.out.println(Thread.currentThread().getName()+"结束");
        };

        Thread t1 = new Thread(r,"t1");
        Thread t2 = new Thread(r,"t2");

        t1.start();
        t2.start();
    }

}

class InitStatic {
    static {
        System.out.println(Thread.currentThread().getName()+"初始化了InitStatic类");
    }
}